package com.qf.controller;


import com.qf.Resp.BaseResp;
import com.qf.borrower.Borrower;
import com.qf.service.BorrowerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class BorrowerController {

    @Autowired
    BorrowerService borrowerService;

    @RequestMapping("/findAll")
    public List<Borrower> findAll(){
//        System.out.println("ssssssssssssssssssssssss");
        List<Borrower> list = borrowerService.findAll();
        System.out.println(list);
        return list;
    }

    @RequestMapping("/findById")
    public Borrower findById(@RequestBody Map map){
        Integer id=(Integer) map.get("id");//将map里的id强转为Integer类型的id
        return borrowerService.findById(Integer.valueOf(id));
    }

    @RequestMapping("/saveOrUpdateg")
    public String saveOrUpdateg(@RequestBody Borrower borrower){
            String str = borrowerService.saveOrUpdate(borrower);
            System.out.println(str);
            return str;
    }

    @RequestMapping("/deleteById")
    public String deleteById(@RequestBody Map map){
        Integer id=(Integer) map.get("id");//将map里的id强转为Integer类型的id
        String s = borrowerService.deleteById(id);
        System.out.println(s);
        return s;
    }

    @RequestMapping("/addAccount")
    public String addAccount(@RequestBody Map map){
        String banknameLoan = (String) map.get("banknameLoan");
        String bankcardnoLoan = (String) map.get("bankcardnoLoan");
        Integer id=1;
        Borrower byId = borrowerService.findById(Integer.valueOf(id));
        byId.setBanknameLoan(banknameLoan);
        byId.setBankcardnoLoan(bankcardnoLoan);

        String s = borrowerService.saveOrUpdate(byId);
        return s;
    }
}
